<template>
  <div>
    <el-drawer :visible.sync="auditVisibility" direction="ttb" :size="'60%'">
      <template #title>
        <span>
          <i class="el-icon-camera"></i>
          <span>审核请假条</span>
        </span>
      </template>
      <el-form
        ref="leaveBill"
        class="leaveBill"
        :model="leaveBill"
        :rules="rules"
      >
        <el-descriptions border>
          <el-descriptions-item label="申请人">{{
            leaveBill.applier
          }}</el-descriptions-item>
          <el-descriptions-item label="请假类型">{{
            leaveBill.leaveType
          }}</el-descriptions-item>
          <el-descriptions-item label="请假开始时间">{{
            leaveBill.startTime
          }}</el-descriptions-item>
          <el-descriptions-item label="请假结束时间">{{
            leaveBill.endTime
          }}</el-descriptions-item>
          <el-descriptions-item label="请假提交时间">{{
            leaveBill.applyTime
          }}</el-descriptions-item>
          <el-descriptions-item label="请假原因">{{
            leaveBill.reason
          }}</el-descriptions-item>
        </el-descriptions>

        <!--                        <el-form-item prop="username" label="申请人：">-->
        <!--                            <el-input v-model.trim="leaveBill.applier">-->
        <!--                            </el-input>-->
        <!--                        </el-form-item>-->

        <el-form-item prop="auditWord" label="审核意见">
          <el-input
            type="textarea"
            :rows="4"
            v-model="leaveBill.auditWord"
            placeholder="审核意见..."
          >
          </el-input>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" icon="el-icon-edit" @click="auditSucceeded"
            >同意请假
          </el-button>
          <el-button type="warning" icon="el-icon-remove" @click="auditFailed"
            >否决请假
          </el-button>
        </el-form-item>
      </el-form>
    </el-drawer>
  </div>
</template>

<script>
// import New from './components/New.vue';
import { leave } from "@/apis";

export default {
  name: "AuditSF",
  components: {
    // New,Old,
  },
  props: {
    sampleP: {
      type: Number,
      default: 0,
    },
  },
  data() {
    return {
      sampleD: "value",
      auditVisibility: false,
      leaveBill: {
        auditWord: "注意安全",
        leaveId: 0,

        applier: "string",
        leaveType: "sickLeave",
        startTime: "2021-10-29T07:34:39.103Z",
        endTime: "2021-10-29T07:34:39.103Z",
        applyTime: "2021-10-29T07:34:39.103Z",
        reason: "string",
        auditor: "string",
        auditTime: "2021-10-29T07:34:39.103Z",

        auditState: "notAudit",
        applyState: "saved",
        version: 0,
        deleted: false,
      },
    };
  },
  computed: {
    // sampleC() {
    //     return this.sampleD+'--';
    // }
  },
  created() {},
  mounted() {},
  methods: {
    sampleM() {},
    appear(id) {
      // this.$message.success("对话框出现: " + id);
      // this.$http({
      //   method: "get",
      //   url: "http://localhost:9091/leave/leaveBill/find/audit/"+id,
      // })
      leave.findAudit(id).then(
        (res) => {
          this.leaveBill = res.data;
          this.$nextTick(() => {
            this.auditVisibility = true;
          });
        },
        (error) => {
          console.log(" request error : " + error.response.status);
        }
      );
    },
    auditSucceeded() {
      // this.$http({
      //   method: "put",
      //   url: "http://localhost:9091/leave/leaveBill/auditSucceeded",
      //   data: this.leaveBill,
      // })
      leave.auditSucceeded(this.leaveBill).then(
        (res) => {
          this.$message.warning(JSON.stringify(res.data));
          this.auditVisibility = false;
          this.$emit("postSubmit");
        },
        (error) => {
          console.log(".leaveBill request error : " + error.response.status);
        }
      );
    },
    auditFailed() {
      // this.$http({
      //   method: "put",
      //   url: "http://localhost:9091/leave/leaveBill/auditFailed",
      //   data: this.leaveBill,
      // })
      leave.auditFailed(this.leaveBill).then(
        (res) => {
          this.$message.warning(JSON.stringify(res.data));
          this.auditVisibility = false;
          this.$emit("postSubmit");
        },
        (error) => {
          console.log(".leaveBill request error : " + error.response.status);
        }
      );
    },
  },
  watch: {
    // sampleC(newValue, oldValue) {
    //
    // }
  },
};
</script>

<!--<style scoped>-->
<style lang="scss" scoped>
.el-form {
  width: 80%;
  margin: 20px auto;
}
</style>
